//Wed Jun  8 16:31:10 CDT 2011
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class LuckyRemainder {
public:
	int getLuckyRemainder(string);
};

int LuckyRemainder::getLuckyRemainder(string x) {
	int N = x.size();
	long long sum = 0LL;
	for(int j=0; j<N; j++){
		sum += (1LL<<N-1) * (x[j] - '0');
		sum %= 9;
	}
	return sum;
}


//Powered by [KawigiEdit] 2.0!
